﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GBFinance.Entity;
using GBFinance.BLL;
using HiLand.Utility.Web;
using GBFinance.Web.Models;
using HiLand.Utility.Finance;
using HiLand.Framework.BusinessCore;
using HiLand.Framework.BusinessCore.BLL;
using HiLand.Utility.Enums;
using HiLand.Utility.Entity;
using HiLand.Utility.Data;
using System.Globalization;
using HiLand.General.Entity;
using HiLand.General.BLL;
using HiLand.General;
using HiLand.Utility4.MVC.Controls;

namespace GBFinance.Web.Controllers
{
    public class UnSecuredController : BaseLoanController
    {
        /*
        #region step0
        public ActionResult Index()
        {
            LoanCookie loanCookie = CookieInfo.Load<UnSecuredLoanCookie>();
            bool isNewBirthLoan = loanCookie.CheckIsNewBirthLoan();
            this.ViewData["isNewBirthLoan"] = isNewBirthLoan;
            return View();
        }

        [HttpPost]
        public ActionResult Index(bool resetLoan = false)
        {
            string result = RequestHelper.GetValue("resetLoan");
            if (result == "resetLoan")
            {
                ResetLoanCookie();
            }
            return View();
        }
        #endregion

        #region step1
        public ActionResult InitialLoanInformation()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }

        public ActionResult UInitialLoanInformation()
        {
            LoanCookie loanCookie = CookieInfo.Load<UnSecuredLoanCookie>();
            LoanBasicEntity entity = null;
            if (loanCookie.LoanGuid == string.Empty)
            {
                entity = new LoanBasicEntity();
            }
            else
            {
                entity = LoanBasicBLL.Get(new Guid(loanCookie.LoanGuid));
            }

            BrokeLoanParam();

            return View(entity);
        }

        [HttpPost]
        public ActionResult UInitialLoanInformation(LoanBasicEntity entity)
        {
            LoanCookie loanCookie = CookieInfo.Load<UnSecuredLoanCookie>();
            bool isNeedSaveCookie = false;
            bool isNewLoan = false;


            if (entity.LoanGuid == Guid.Empty)
            {
                Guid loanGuid = Guid.Empty;
                if (loanCookie.LoanGuid == string.Empty)
                {
                    loanGuid = Guid.NewGuid();
                    loanCookie.LoanGuid = loanGuid.ToString();
                    isNeedSaveCookie = true;
                }
                else
                {
                    loanGuid = new Guid(loanCookie.LoanGuid);
                }
                entity.LoanGuid = loanGuid;
                isNewLoan = true;
            }
            else
            {
                LoanBasicEntity entityLoaded = LoanBasicBLL.Get(entity.LoanGuid);
                entity.CheckDate = entityLoaded.CheckDate;
                entity.CheckUserID = entityLoaded.CheckUserID;
                entity.LoanDate = entityLoaded.LoanDate;
                entity.LoanInterest = entityLoaded.LoanInterest;
                entity.LoanStatus = entityLoaded.LoanStatus;
                entity.LoanTermType = entityLoaded.LoanTermType;
                entity.LoanType = entityLoaded.LoanType;
                entity.PropertyNames = entityLoaded.PropertyNames;
                entity.PropertyValues = entityLoaded.PropertyValues;
            }


            if (entity.LoanUserID == Guid.Empty)
            {
                Guid enterpriseGuid = Guid.Empty;
                if (loanCookie.EnterpriseGuid == string.Empty)
                {
                    enterpriseGuid = Guid.NewGuid();
                    loanCookie.EnterpriseGuid = enterpriseGuid.ToString();
                    isNeedSaveCookie = true;
                }
                else
                {
                    enterpriseGuid = new Guid(loanCookie.EnterpriseGuid);
                }

                entity.LoanUserID = enterpriseGuid;
            }

            SetLoanStep(10);

            if (isNeedSaveCookie == true)
            {
                loanCookie.Save();
            }

            bool isSuccessful = false;
            if (isNewLoan == true)
            {
                entity.LoanTermType = PaymentTermType.Monthly;
                entity.LoanDate = DateTime.Now;
                entity.LoanInterest = new LoanBasicSetting().SecuredLoansAnnualInterest;
                entity.LoanStatus = LoanStatuses.UserUnCompleted;
                entity.LoanType = LoanTypes.UnSecured;
                isSuccessful = LoanBasicBLL.Create(entity);
            }
            else
            {
                isSuccessful = LoanBasicBLL.Update(entity);
            }

            var DataObject = new LogicStatusInfo { IsSuccessful = isSuccessful };

            return Json(DataObject);
        }
        #endregion

        #region step2
        public ActionResult AboutTheApplicants()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }

        /// <summary>
        /// 企业负责人列表
        /// </summary>
        /// <returns></returns>
        public ActionResult UApplicantList()
        {
            BrokeLoanParam();

            List<IBusinessUser> userList = GetApplicantList();
            return View(userList);
        }

        [HttpPost]
        public ActionResult UApplicantList(Guid? entityGuidToDelete)
        {
            BrokeLoanParam();

            if (entityGuidToDelete.HasValue && entityGuidToDelete.Value != Guid.Empty)
            {
                BusinessUserBLL.DeleteUser(entityGuidToDelete.Value);
            }

            List<IBusinessUser> userList = GetApplicantList();
            return View(userList);
        }

        private List<IBusinessUser> GetApplicantList()
        {
            List<IBusinessUser> userList = BusinessUserBLL.GetUsersByDepartment(Miscs.CurrentLoanSimpleInfo.EnterpriseGuid);
            return userList;
        }

        public ActionResult UApplicantDetail(Guid? applicantGuid)
        {
            IBusinessUser applicantUser = new BusinessUser();
            ResidentalEntity residentalEntity = new ResidentalEntity();
            ResidentalEntity residentalEntityPre = new ResidentalEntity();
            if (applicantGuid.HasValue)
            {
                applicantUser = BusinessUserBLL.Get(applicantGuid.Value);
                string whereClause = string.Format("ResidentalUserGuid='{0}'", applicantGuid.Value);
                List<ResidentalEntity> residentalList = ResidentalBLL.GetList(whereClause);
                if (residentalList != null)
                {
                    if (residentalList.Count > 0)
                    {
                        residentalEntity = residentalList[0];
                    }

                    if (residentalList.Count > 1)
                    {
                        residentalEntityPre = residentalList[1];
                    }
                }
            }

            this.ViewBag.ResidentalEntity = residentalEntity;
            this.ViewBag.ResidentalEntityPre = residentalEntityPre;

            return View(applicantUser);
        }

        [HttpPost]
        public ActionResult UApplicantDetail(BusinessUser applicantUser)
        {
            if (applicantUser.UserBirthDay == DateTimeHelper.Min)
            {
                string birthDayFromRequest = RequestHelper.GetValue("UserBirthDay");

                DateTime userBirthDay = DateTimeHelper.Min;

                //TODO:这个地方处理略有奇怪，目前只能手工解析日期字符串形成日期
                try
                {
                    if (string.IsNullOrWhiteSpace(birthDayFromRequest) == false)
                    {
                        string[] birthDayStrings = birthDayFromRequest.Split('/');
                        if (birthDayStrings.Length == 3)
                        {
                            int userBirthYear = Convert.ToInt32(birthDayStrings[2]);
                            int userBirthMonth = Convert.ToInt32(birthDayStrings[1]);
                            int userBirthDate = Convert.ToInt32(birthDayStrings[0]);
                            userBirthDay = new DateTime(userBirthYear, userBirthMonth, userBirthDate);
                        }
                    }
                }
                catch { }

                //DateTime.TryParseExact(birthDayFromRequest,"dd/MM/yyyy", Misc.CurrentCultureInfo, DateTimeStyles.None, out userBirthDay);
                ////DateTime.TryParse(birthDayFromRequest, Misc.CurrentCultureInfo, DateTimeStyles.None, out userBirthDay);
                applicantUser.UserBirthDay = userBirthDay;
            }

            LogicStatusInfo statusInfo = new LogicStatusInfo();

            LoanCookie loanCookie = CookieInfo.Load<UnSecuredLoanCookie>();
            if (applicantUser.UserGuid == Guid.Empty)
            {
                applicantUser.UserGuid = Guid.NewGuid();
                applicantUser.DepartmentCode = "outer";
                applicantUser.DepartmentGuid = new Guid(loanCookie.EnterpriseGuid);
                applicantUser.UserRegisterDate = DateTime.Now;
                applicantUser.UserStatus = CommonStatuses.Normal;
                applicantUser.UserType = UserTypes.CommonUser;
                applicantUser.UserName = Guid.NewGuid().ToString();

                CreateUserRoleStatuses createStatus = CreateUserRoleStatuses.Successful;
                BusinessUserBLL.CreateUser(applicantUser, out createStatus);
                if (createStatus == CreateUserRoleStatuses.Successful)
                {
                    statusInfo.IsSuccessful = true;
                    statusInfo.Message = string.Empty;
                }
                else
                {
                    statusInfo.IsSuccessful = false;
                    statusInfo.Message = createStatus.ToString();
                }
            }
            else
            {
                IBusinessUser originalUser = BusinessUserBLL.Get(applicantUser.UserGuid);
                applicantUser.DepartmentCode = originalUser.DepartmentCode;
                applicantUser.DepartmentGuid = originalUser.DepartmentGuid;
                applicantUser.UserRegisterDate = originalUser.UserRegisterDate;
                applicantUser.UserStatus = originalUser.UserStatus;
                applicantUser.UserType = originalUser.UserType;
                applicantUser.UserName = originalUser.UserName;

                bool isSuccessful = BusinessUserBLL.UpdateUser(applicantUser);
                if (isSuccessful == true)
                {
                    statusInfo.IsSuccessful = true;
                    statusInfo.Message = string.Empty;
                }
                else
                {
                    statusInfo.IsSuccessful = false;
                    statusInfo.Message = "error in updating";
                }
            }

            string residentalGuid = RequestHelper.GetValue("ResidentalGuid");
            string residentalGuidPre = RequestHelper.GetValue("ResidentalGuidPre");


            ResidentalEntity residentalEntity = CollectResidentalInfo();
            ResidentalEntity residentalEntityPre = CollectResidentalInfo("Pre");

            string residentalStatusString = RequestHelper.GetValue("ResidentialStatus");
            int residentalStatus = (int)ResidentalTypes.OwnHomeWithMortgage;
            int.TryParse(residentalStatusString, out residentalStatus);
            residentalEntity.ResidentialStatus = residentalStatus;

            residentalEntity.ResidentalUserGuid = applicantUser.UserGuid;
            residentalEntityPre.ResidentalUserGuid = applicantUser.UserGuid;

            if (string.IsNullOrWhiteSpace(residentalGuid) == true || residentalGuid == Guid.Empty.ToString())
            {
                ResidentalBLL.Create(residentalEntity);
            }
            else
            {
                ResidentalBLL.Update(residentalEntity);
            }


            if (string.IsNullOrWhiteSpace(residentalGuidPre) == true || residentalGuidPre == Guid.Empty.ToString())
            {
                ResidentalBLL.Create(residentalEntityPre);
            }
            else
            {
                ResidentalBLL.Update(residentalEntityPre);
            }

            SetLoanStep(20);

            return Json(statusInfo);
        }

        #region 辅助方法
        private ResidentalEntity CollectResidentalInfo(string prefix = "")
        {
            ResidentalEntity residentalEntity = new ResidentalEntity();
            residentalEntity.ApartmentNo = RequestHelper.GetValue(prefix + "UnitApartmentNo");
            residentalEntity.PostCode = RequestHelper.GetValue(prefix + "Postcode");

            int residentalMonthes = 0;
            int residentalYears = 0;
            int.TryParse(RequestHelper.GetValue(prefix + "AddressMonths"), out residentalMonthes);
            int.TryParse(RequestHelper.GetValue(prefix + "AddressYears"), out residentalYears);
            residentalEntity.ResidentalMonths = residentalMonthes;
            residentalEntity.ResidentalYears = residentalYears;

            residentalEntity.State = RequestHelper.GetValue(prefix + "State");
            residentalEntity.Street = RequestHelper.GetValue(prefix + "StreetNoAndName");
            residentalEntity.Suburb = RequestHelper.GetValue(prefix + "Suburb");

            return residentalEntity;
        }
        #endregion
        #endregion

        #region step3
        public ActionResult AboutYourBusiness()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }


        public ActionResult UAboutYourBusiness()
        {
            BrokeLoanParam();

            EnterpriseEntity enterpriseEntity = new EnterpriseEntity();
            EnterpriseEntity enterpriseRef1 = new EnterpriseEntity();
            EnterpriseEntity enterpriseRef2 = new EnterpriseEntity();

            LoanCookie loanCookie = CookieInfo.Load<UnSecuredLoanCookie>();
            string enterpriseGuidString = loanCookie.EnterpriseGuid;
            Guid enterpriseGuid = Guid.Empty;

            if (string.IsNullOrWhiteSpace(enterpriseGuidString) == false && enterpriseGuidString != Guid.Empty.ToString())
            {
                enterpriseGuid = new Guid(enterpriseGuidString);
                enterpriseEntity = EnterpriseBLL.Get(enterpriseGuid);
                if (enterpriseEntity == null)
                {
                    enterpriseEntity = new EnterpriseEntity();
                }
                string whereClause = string.Format("AssociatedEnterpriseGuid='{0}'", enterpriseGuidString);
                List<EnterpriseEntity> enterpriseRefList = EnterpriseBLL.GetList(whereClause);
                if (enterpriseRefList != null)
                {
                    if (enterpriseRefList.Count > 0)
                    {
                        enterpriseRef1 = enterpriseRefList[0];
                    }

                    if (enterpriseRefList.Count > 1)
                    {
                        enterpriseRef2 = enterpriseRefList[1];
                    }
                }
            }

            this.ViewBag.EnterpriseRef1 = enterpriseRef1;
            this.ViewBag.EnterpriseRef2 = enterpriseRef2;

            return View(enterpriseEntity);
        }

        [HttpPost]
        public ActionResult UAboutYourBusiness(EnterpriseEntity entity)
        {
            LogicStatusInfo logicStatusInfo = new LogicStatusInfo();

            LoanCookie loanCookie = CookieInfo.Load<UnSecuredLoanCookie>();
            string enterpriseGuidString = loanCookie.EnterpriseGuid;
            Guid enterpriseGuid = Guid.Empty;
            if (string.IsNullOrWhiteSpace(enterpriseGuidString) || enterpriseGuidString == Guid.Empty.ToString())
            {
                enterpriseGuid = Guid.NewGuid();
            }
            else
            {
                enterpriseGuid = new Guid(enterpriseGuidString);
            }

            EnterpriseEntity enterpriseRef1 = CollecteEnterpriseRef("Ref1");
            EnterpriseEntity enterpriseRef2 = CollecteEnterpriseRef("Ref2");

            enterpriseRef1.AssociatedEnterpriseGuid = enterpriseGuid;
            enterpriseRef2.AssociatedEnterpriseGuid = enterpriseGuid;


            if (entity.EnterpriseID == 0)
            {
                entity.EnterpriseGuid = enterpriseGuid;
                logicStatusInfo.IsSuccessful = EnterpriseBLL.Create(entity);
            }
            else
            {
                logicStatusInfo.IsSuccessful = EnterpriseBLL.Update(entity);
            }

            if (enterpriseRef1.EnterpriseGuid == Guid.Empty)
            {
                enterpriseRef1.EnterpriseGuid = Guid.NewGuid();
                EnterpriseBLL.Create(enterpriseRef1);
            }
            else
            {
                EnterpriseBLL.Update(enterpriseRef1);
            }

            if (enterpriseRef2.EnterpriseGuid == Guid.Empty)
            {
                enterpriseRef2.EnterpriseGuid = Guid.NewGuid();
                EnterpriseBLL.Create(enterpriseRef2);
            }
            else
            {
                EnterpriseBLL.Update(enterpriseRef2);
            }

            SetLoanStep(30);

            return Json(logicStatusInfo);
        }

        private EnterpriseEntity CollecteEnterpriseRef(string postFix)
        {
            EnterpriseEntity entity = new EnterpriseEntity();
            string enterpriseGuidRef = RequestHelper.GetValue("EnterpriseGuid" + postFix);
            if (string.IsNullOrWhiteSpace(enterpriseGuidRef))
            {
                entity.EnterpriseGuid = Guid.Empty;
            }
            else
            {
                entity.EnterpriseGuid = new Guid(enterpriseGuidRef);
            }

            entity.ContactPerson = RequestHelper.GetValue("ContactName" + postFix);
            entity.CompanyName = RequestHelper.GetValue("CompanyName" + postFix);
            entity.Telephone = RequestHelper.GetValue("Telephone" + postFix);

            return entity;
        }
        #endregion

        #region step4
        public ActionResult LiabilityStatement()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }

        public ActionResult ULiabilityStatementWrapper()
        {
            BrokeLoanParam();
            return View();
        }

        public ActionResult ULiabilityStatementList()
        {
            BrokeLoanParam();

            List<LiabilityEntity> entityList = GetLiabilityList();
            return View(entityList);
        }

        [HttpPost]
        public ActionResult ULiabilityStatementList(Guid? entityGuidToDelete)
        {
            BrokeLoanParam();


            if (entityGuidToDelete.HasValue && entityGuidToDelete.Value != Guid.Empty)
            {
                LiabilityBLL.Delete(entityGuidToDelete.Value);
            }

            List<LiabilityEntity> entityList = GetLiabilityList();
            return View(entityList);
        }

        

        public ActionResult ULiabilityStatementDetails(Guid? ItemGuid)
        {
            LiabilityEntity entity = null;
            if (ItemGuid.HasValue)
            {
                entity = LiabilityBLL.Get(ItemGuid.Value);
            }
            else
            {
                entity = new LiabilityEntity();
            }

            BrokeLoanParam();

            return View(entity);
        }

        [HttpPost]
        public ActionResult ULiabilityStatementDetails(LiabilityEntity entity)
        {
            LogicStatusInfo logicStatusInfo = new LogicStatusInfo();

            entity.UserGuid = Miscs.CurrentLoanSimpleInfo.EnterpriseGuid;

            if (entity.LiabilityGuid == Guid.Empty)
            {
                entity.LiabilityGuid = Guid.NewGuid();
                logicStatusInfo.IsSuccessful = LiabilityBLL.Create(entity);
            }
            else
            {
                logicStatusInfo.IsSuccessful = LiabilityBLL.Update(entity);
            }

            SetLoanStep(40);

            return Json(logicStatusInfo);
        }

        #region 辅助方法
        private List<LiabilityEntity> GetLiabilityList()
        {
            List<LiabilityEntity> entityList = new List<LiabilityEntity>();
            string whereCluase = string.Format("UserGuid='{0}'", Miscs.CurrentLoanSimpleInfo.EnterpriseGuid.ToString());
            entityList = LiabilityBLL.GetList(whereCluase);
            return entityList;
        }
        #endregion
        #endregion

        #region step5
        public ActionResult AssetStatement()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }

        public ActionResult UAssetStatementWrapper()
        {
            BrokeLoanParam();
            return View();
        }

        public ActionResult UAssetStatementList()
        {
            BrokeLoanParam();

            List<IncomeAssetEntity> entityList = GetAssetStatementList();
            return View(entityList);
        }

        [HttpPost]
        public ActionResult UAssetStatementList(Guid? entityGuidToDelete)
        {
            BrokeLoanParam();

            if (entityGuidToDelete.HasValue && entityGuidToDelete.Value != Guid.Empty)
            {
                IncomeAssetBLL.Delete(entityGuidToDelete.Value);
            }

            List<IncomeAssetEntity> entityList = GetAssetStatementList();
            return View(entityList);
        }


        public ActionResult UAssetStatementDetails(Guid? ItemGuid)
        {
            IncomeAssetEntity entity = null;
            if (ItemGuid.HasValue)
            {
                entity = IncomeAssetBLL.Get(ItemGuid.Value);
            }
            else
            {
                entity = new IncomeAssetEntity();
            }

            BrokeLoanParam();

            return View(entity);
        }

        [HttpPost]
        public ActionResult UAssetStatementDetails(IncomeAssetEntity entity)
        {
            BrokeLoanParam();

            LogicStatusInfo logicStatusInfo = new LogicStatusInfo();

            entity.UserGuid = Miscs.CurrentLoanSimpleInfo.EnterpriseGuid;

            if (entity.ItemGuid == Guid.Empty)
            {
                entity.ItemGuid = Guid.NewGuid();
                logicStatusInfo.IsSuccessful = IncomeAssetBLL.Create(entity);
            }
            else
            {
                logicStatusInfo.IsSuccessful = IncomeAssetBLL.Update(entity);
            }

            SetLoanStep(50);

            return Json(logicStatusInfo);
        }

        #region 辅助方法
        private List<IncomeAssetEntity> GetAssetStatementList()
        {
            List<IncomeAssetEntity> entityList = new List<IncomeAssetEntity>();

            string whereCluase = string.Format("UserGuid='{0}'", Miscs.CurrentLoanSimpleInfo.EnterpriseGuid.ToString());
            entityList = IncomeAssetBLL.GetList(whereCluase);
            return entityList;
        }
        #endregion
        #endregion

        #region step6
        public ActionResult AboutTheSecurities()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }

        public ActionResult UAboutTheSecuritiesDetails(Guid? ItemGuid)
        {
            SecuredPropertyEntity entity = null;
            if (ItemGuid.HasValue)
            {
                entity = SecuredPropertyBLL.Get(ItemGuid.Value);
            }
            else
            {
                entity = new SecuredPropertyEntity();
            }

            return View(entity);
        }

        [HttpPost]
        public ActionResult UAboutTheSecuritiesDetails(SecuredPropertyEntity securedPropertyEntity)
        {
            LogicStatusInfo logicStatusInfo = new LogicStatusInfo();

            securedPropertyEntity.UserGuid = Miscs.CurrentLoanSimpleInfo.EnterpriseGuid;

            if (securedPropertyEntity.ItemGuid == Guid.Empty)
            {
                securedPropertyEntity.ItemGuid = Guid.NewGuid();
                logicStatusInfo.IsSuccessful = SecuredPropertyBLL.Create(securedPropertyEntity);
            }
            else
            {
                logicStatusInfo.IsSuccessful = SecuredPropertyBLL.Update(securedPropertyEntity);
            }

            SetLoanStep(60);

            return Json(logicStatusInfo);
        }

        public ActionResult UAboutTheSecuritiesList()
        {
            BrokeLoanParam();

            List<SecuredPropertyEntity> securedPropertyList = GetSecuredPropertyList();
            return View(securedPropertyList);
        }

        [HttpPost]
        public ActionResult UAboutTheSecuritiesList(Guid? entityGuidToDelete)
        {
            BrokeLoanParam();

            if (entityGuidToDelete.HasValue && entityGuidToDelete.Value != Guid.Empty)
            {
                SecuredPropertyBLL.Delete(entityGuidToDelete.Value);
            }

            List<SecuredPropertyEntity> securedPropertyList = GetSecuredPropertyList();
            return View(securedPropertyList);
        }

        #region 辅助方法
        private List<SecuredPropertyEntity> GetSecuredPropertyList()
        {
            List<SecuredPropertyEntity> securedPropertyList = new List<SecuredPropertyEntity>();
            string whereCluase = string.Format("UserGuid='{0}'", Miscs.CurrentLoanSimpleInfo.EnterpriseGuid.ToString());
            securedPropertyList = SecuredPropertyBLL.GetList(whereCluase);
            return securedPropertyList;
        }
        #endregion
        #endregion

        #region step7
        public ActionResult BusinessBankDetails()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }

        public ActionResult UBusinessBankDetails()
        {
            BrokeLoanParam();

            BankEntity bankEntity = new BankEntity();

            LoanCookie loanCookie = CookieInfo.Load<UnSecuredLoanCookie>();
            string enterpriseGuidString = loanCookie.EnterpriseGuid;
            Guid enterpriseGuid = Guid.Empty;
            if (string.IsNullOrWhiteSpace(enterpriseGuidString) || enterpriseGuidString == Guid.Empty.ToString())
            {
                //enterpriseGuid = Guid.NewGuid();
            }
            else
            {
                //enterpriseGuid = new Guid(enterpriseGuidString);
                string whereClause = string.Format("UserGuid='{0}'", enterpriseGuidString);
                List<BankEntity> bankList = BankBLL.GetList(whereClause);
                if (bankList != null && bankList.Count > 0)
                {
                    bankEntity = bankList[0];
                }
            }


            return View(bankEntity);
        }

        [HttpPost]
        public ActionResult UBusinessBankDetails(BankEntity bankEntity)
        {
            LogicStatusInfo logicStatusInfo = new LogicStatusInfo();
            LoanCookie loanCookie = CookieInfo.Load<UnSecuredLoanCookie>();
            string enterpriseGuidString = loanCookie.EnterpriseGuid;
            Guid enterpriseGuid = Guid.Empty;
            if (string.IsNullOrWhiteSpace(enterpriseGuidString) || enterpriseGuidString == Guid.Empty.ToString())
            {
                enterpriseGuid = Guid.NewGuid();
            }
            else
            {
                enterpriseGuid = new Guid(enterpriseGuidString);
            }
            bankEntity.UserGuid = enterpriseGuid;

            if (bankEntity.BankGuid == Guid.Empty)
            {
                bankEntity.BankGuid = Guid.NewGuid();

                logicStatusInfo.IsSuccessful = BankBLL.Create(bankEntity);
            }
            else
            {
                logicStatusInfo.IsSuccessful = BankBLL.Update(bankEntity);
            }

            SetLoanStep(70);

            return Json(logicStatusInfo);
        }
        #endregion

        #region step8
        public ActionResult ApplicationSummary()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }

        [HttpPost]
        public ActionResult ApplicationSummary(string onlyPlaceHolder)
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            SetLoanStep(80);
            LogicStatusInfo logicStatusInfo = new LogicStatusInfo(true);
            return View(logicStatusInfo);
        }

        public ActionResult UApplicationSummary()
        {
            return View();
        }
        #endregion

        #region step9
        public ActionResult SubmitApplication()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }

        [HttpPost]
        public ActionResult SubmitApplication(string signedFullName)
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            LogicStatusInfo logicStatusInfo = new LogicStatusInfo();
            if (string.IsNullOrWhiteSpace(signedFullName) == false)
            {
                EnterpriseEntity enterpriseEntity = EnterpriseBLL.Get(Miscs.CurrentLoanSimpleInfo.EnterpriseGuid);
                if (enterpriseEntity != null)
                {
                    enterpriseEntity.CompanyNameShort = signedFullName;
                    logicStatusInfo.IsSuccessful = EnterpriseBLL.Update(enterpriseEntity);
                }

                LoanBasicEntity loanEntity = LoanBasicBLL.Get(Miscs.CurrentLoanSimpleInfo.LoanGuid);
                if (loanEntity != null)
                {
                    loanEntity.LoanStatus = LoanStatuses.UserCompleted;
                    logicStatusInfo.IsSuccessful = LoanBasicBLL.Update(loanEntity);
                }
                //SetLoanStep(90);
                //清空Loan的cookie
                LoanCookie loanCookie = LoanCookie.Load<UnSecuredLoanCookie>();
                loanCookie.Reset();
            }

            return Json(logicStatusInfo);
        }
        #endregion

        #region step10
        public ActionResult FinalStep()
        {
            this.ViewData["_Layout"] = CodeUtils.LayoutPathForUnSecured;
            return View();
        }
        #endregion

        #region 辅助方法
        public ActionResult Test()
        {
            return View();
        }
        /// <summary>
        /// 在cookie中设置贷款的步骤数
        /// </summary>
        /// <param name="step"></param>
        private static void SetLoanStep(int step)
        {
            SetLoanStep<UnSecuredLoanCookie>(step);
        }

        /// <summary>
        /// 重置LoanCookie
        /// </summary>
        private static void ResetLoanCookie()
        {
            ResetLoanCookie<UnSecuredLoanCookie>();
        }

        /// <summary>
        /// 创建新的贷款Cookie
        /// </summary>
        /// <param name="isAlwaysCreateNew">是否总是创建新的Cookie（即原来存在的情况下会覆盖）</param>
        private static void CreateNewLoanCookie(bool isAlwaysCreateNew = false)
        {
            CreateNewLoanCookie<UnSecuredLoanCookie>(isAlwaysCreateNew);
        }
        #endregion
         */
    }
}
